package com.sm.scorpio.ui.activity.chat;

import android.content.Intent;
import android.net.Uri;
import android.os.Bundle;
import android.view.View;

import androidx.recyclerview.widget.DefaultItemAnimator;
import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;

import com.sm.chatinputlibrary.ChatInput;
import com.sm.imlibrary.presenter.ChatPresenter;
import com.sm.scorpio.R;
import com.sm.scorpio.ui.base.BaseActivity;

import java.util.ArrayList;
import java.util.List;

public class ChatActivity extends BaseActivity {
    public static final String REQUEST_KEY_IDENTIFY = "identify";
    private ChatInput chatInput;
    private ChatAdapter mAdapter;
    private RecyclerView recyclerView;
    private List<ChatBean> mChatBeans = new ArrayList<>();
    private ChatPresenter presenter;
    private String identify;

    @Override
    protected int onCreateLayout() {
        return R.layout.activity_chat;
    }

    @Override
    protected void onInit(Bundle savedInstanceState) {
        if (savedInstanceState != null) {
            identify = savedInstanceState.getString(REQUEST_KEY_IDENTIFY);
        } else {
            identify = getIntent().getStringExtra(REQUEST_KEY_IDENTIFY);
        }
        showBackBtn();
        setBasicTitle("聊天");
        chatInput = v.getView(R.id.chatInput);
        chatInput.setOnChatInputEventListener(onChatInputEventListener);
        recyclerView = v.getView(R.id.recyclerView);
        LinearLayoutManager manager = new LinearLayoutManager(this);
        manager.setOrientation(LinearLayoutManager.VERTICAL);
        manager.setReverseLayout(true);
        manager.setStackFromEnd(true);
        v.setRecyclerViewAdapter(R.id.recyclerView, mAdapter = new ChatAdapter(mChatBeans))
                .setRecyclerViewLayoutManager(R.id.recyclerView, manager);
        recyclerView.setItemAnimator(new DefaultItemAnimator());
//        presenter = new ChatPresenter(this);
    }

    @Override
    protected void onNewIntent(Intent intent) {
        super.onNewIntent(intent);
        setIntent(intent);
        onInit(null);
    }

    @Override
    protected void onSaveInstanceState(Bundle outState) {
        super.onSaveInstanceState(outState);
        outState.putString(identify,REQUEST_KEY_IDENTIFY);
    }

    private ChatInput.OnChatInputEventListener onChatInputEventListener = new ChatInput.OnChatInputEventListener() {
        @Override
        public boolean onChatMessage(String message) {
            return true;
        }

        @Override
        public void onSelectedPicture(List<Uri> uris) {

        }

        @Override
        public void onSelectedFile(String path) {

        }
    };

    @Override
    public void onClick(View view) {
        super.onClick(view);
    }
}
